<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/login.css">
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>

    <script type="text/javascript">
        $(function () {
           $("#loginForm").ajaxForm(function (data) {
               if (data.success) {
                   $(document).dialog({
                       type : 'confirm',
                       style: 'ios',
                       titleShow: false,
                       overlayClose: true,
                       content: "登录成功",
                       buttons: [{
                           name:"确定",
                           callback: function() {
                               //登录成功，存入sessionStorage中
                               var user=JSON.stringify(data.obj);
                               sessionStorage.setItem("user",user);

                               parent.location.href="/index.html";
                           }
                       }]
                   });

               }else{
                   $(document).dialog({
                       titleShow: false,
                       autoClose: 2000,
                       content: "登录失败！"
                   });
               }
           })

            //把json字符串转成对象
            var struser=sessionStorage.getItem("user");
            var user=JSON.parse(struser);
            console.log(user);
            //共享到
            $("#loginForm").renderValues(user);


        });
    </script>
</head>
<body>
<div class="container">
    <h5>登录</h5>

    <div class="card card-container ">
        <i id="profile-img" class="fa fa-user-circle fa-5x profile-img"></i>
        <form class="form-signin" id="loginForm" action="/sessions" method="post">
            <input type="email" name="email"  class="form-control badge-pill"
                   value="bunny@wolfcode.cn" placeholder="邮箱" render-value="email">
            <input type="password" name="password" value="1" class="form-control badge-pill" placeholder="密码">
            <a href="#" class="forgot-password">
                忘记密码？
            </a>
            <button class="btn btn-lg badge-pill" type="submit">登录</button>
        </form>
    </div>


    <a href="/register.html" class="registerLink">
        新用户？点击这里注册
    </a>
</div>

</body>
</html>
